package com.example.springcloudribbon.contorller;

import com.example.springcloudribbon.pojo.ClientPo;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@RestController
public class RibbonController {
    @RequestMapping("ribbon")
    private String ribbon() {
        return "ribbon3";
    }


    @RequestMapping("ribbonDemo2")
    private String ribbonDemo(String name, String age) {
        return "name:" + name + ",age:" + age;
    }

    @RequestMapping("ribbonDemo3/{name}/{age}")
    private String ribbonDemo2(@PathVariable String name, @PathVariable Integer age) {
        return "name:" + name + ",age:" + age;
    }

    @RequestMapping("ribbonDemo4")
    private String ribbonDemo4(String name, String age, @RequestBody Map<String, Object> map) {
        System.out.println(map);
        return "name:" + name + ",age:" + age;
    }

    @RequestMapping("ribbonDemo5")
    private ClientPo ribbonDemo5() {
        return new ClientPo(1, "liaofan");
    }

    @RequestMapping("ribbonDemo6")
    private List<ClientPo> ribbonDemo6() {
        List<ClientPo> clientPoList = new ArrayList<ClientPo>();
        clientPoList.add(new ClientPo(1, "liaofan"));
        clientPoList.add(new ClientPo(2, "bill gates"));
        return clientPoList;
    }


    @RequestMapping("returnRequestBody")
    public ClientPo demo5(@RequestBody ClientPo clientPo) {
        return clientPo;
    }

    /**
     * 返回普通表单参数
     *
     * @return
     */
    @RequestMapping("retrunNormalFormDataDemo6")
    public ClientPo retrunNormalFormDataDemo6(@RequestParam ClientPo clientPo) {
        return clientPo;
    }

    /**
     * 不使用请求合并的时候
     * @param name
     * @return
     */
    @RequestMapping("feignWithHystrixCollasper")
    public String feignWithHystrixCollasper(String name) {
        return "返回的HystrixCollasper的Name:" + name;
    }


    /**
     * 使用请求合并的时候
     * @param names
     * @return
     */
    @RequestMapping("feignWithHystrixCollasperList")
    public List<String> feignWithHystrixCollasper_Hb(@RequestBody List<String> names) {
        System.out.println("names:" + names);
        List<String> list = new ArrayList<String>();
        list.add("a");
        list.add("b");
        return  list;
    }



}
